package com.shop.cereshop.business.service.business.impl;

import com.shop.cereshop.commons.domain.common.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shop.cereshop.business.dao.business.CereBusinessAdviceDAO;
import com.shop.cereshop.business.page.advice.BusinessAdviceVO;
import com.shop.cereshop.business.service.business.CereBusinessAdviceService;
import com.shop.cereshop.commons.domain.business.CereBusinessAdvice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商家经营建议服务实现类
 */
@Service
public class CereBusinessAdviceServiceImpl implements CereBusinessAdviceService {

    @Autowired
    private CereBusinessAdviceDAO cereBusinessAdviceDAO;

    @Override
    public void save(CereBusinessAdvice cereBusinessAdvice) {
        cereBusinessAdviceDAO.insert(cereBusinessAdvice);
    }

    @Override
    public void update(CereBusinessAdvice cereBusinessAdvice) {
        cereBusinessAdviceDAO.updateById(cereBusinessAdvice);
    }

    @Override
    public void delete(Long adviceId) {
        cereBusinessAdviceDAO.deleteById(adviceId);
    }

    @Override
    public CereBusinessAdvice getById(Long adviceId) {
        return cereBusinessAdviceDAO.selectById(adviceId);
    }

    @Override
    public Page<BusinessAdviceVO> findByShopId(Integer pageNum, Integer pageSize, Long shopId) {
        //构建分页参数
        PageHelper.startPage(pageNum, pageSize);
        List<BusinessAdviceVO> list =  cereBusinessAdviceDAO.findByShopId(shopId);
        PageInfo<BusinessAdviceVO> pageInfo = new PageInfo<>(list);
        Page<BusinessAdviceVO> page=new Page(pageInfo.getList(),pageInfo.getTotal());
        return page;
    }
}